package leetcode.sword;

public class Solution56_1 {

    public int[] singleNumbers(int[] nums) {
        //先找到这两个不同数字的不同位
        int diff = 0;
        for (int num : nums) {
            diff ^= num;
        }
        int m = 1;//记录不同的最低位
        while ((diff&m)==0) m<<=1;

        //找两个只出现一次数字
        int a = 0, b = 0;
        for (int num : nums) {
            if((num&m)==0) a^=num;
            else b^=num;
        }
        return new int[]{a,b};
    }
}
